/*
 * Created by 18012 on 2018/4/14.
 * desc:
 */
package com.example.springboot.restapi.base;


/**
 *
 ************************************************************
 * @Description:前后端分离的api响应格式
 * ==========================================================
 * @author wenyi  2018/1/17 22:00
 * @see
 * @since JDK1.8
 ************************************************************
 */
public class Response<T> {

    /**
     * 响应的数据体
     */
    private T date;

    /**
     * 响应的参数
     */
    private Mate mate;

    public Response() {
        this.mate = new Mate();
    }

    public Response success(T date){
        this.mate = new Mate(1,"成功");
        this.date = date;
        return this;
    }

    public Response success(){
        this.mate = new Mate(1,"成功");
        return this;
    }

    public Response failure(String message){
        this.mate = new Mate(0,message);
        return this;
    }

    public Response failure(){
        this.mate = new Mate(0,"失败");
        return this;
    }

    public Response failure(Integer code,String message){
        this.mate = new Mate(code,message);
        return this;
    }

    public void setMessage(String message){
        this.mate.setMsg(message);
    }

    public void setCode(Integer code){
        this.mate.setCode(code);
    }

    public void setDate(T date){
        this.date = date;
    }

    public T getDate(){
        return date;
    }

    public Mate getMate(){
        return mate;
    }
}
